home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Tools & Apps / Testing & Debugging / Robix V1.0 / EthernetTests.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-21  |  5.1 KB  |  194 lines  |  [TEXT/MPS ]

  1. /*
  2. *
  3. * © Copyright 1991, Rob Glanville
  4. *
  5. * by Rob Glanville
  6. *
  7. * 17 June 91
  8. *
  9. * EthernetTests.c - Channel command based ethernet tests.
  10. *
  11. */
  12.  
  13. /*
  14. *
  15. * This module tests the MACE Ethernet peripheral using the channel command
  16. * structure outlined for the Mazda RISC engine. A pointer to a parameter
  17. * block is passed and this block is only used to return the results. This
  18. * module was primarily written for bring-up and performs five tests. Some
  19. * portions of the tests require an external analyzer to capture the results
  20. * and generate packet traffic.
  21. *
  22. * Some hard facts:
  23. * 1) The data is always an incrementing pattern and is 1500 bytes long
  24. * 2) The destination address for the first packet will be 1000E0280877
  25. *    which is the address of an Ethernet NuBus card.
  26. * 3) The source address will be 526F6220472E (Rob G.)
  27. * 4) The packets will have the following format;
  28. *    6 bytes for destination address, 6 bytes for source address, 2 bytes
  29. *    for command or length, 1500 bytes for data, 4 bytes for CRC. 1518 Total
  30. * 5) CRC data is appended to the packet by MACE hardware.
  31. *
  32. */
  33.  
  34. /* Miscellanious defines */
  35. #define UBYTE    unsigned char
  36. #define UWORD    unsigned short
  37. #define    ULONG    unsigned long
  38. #define Null    0x00000000
  39. #define True    0xFFFFFFFF
  40. #define False    0x00000000
  41. #define    PBYTE    *(unsigned char *)    /* Used for physical address casting */
  42. #define    PWORD    *(unsigned short *)    /* Used for physical address casting */
  43. #define    PLONG    *(unsigned long *)    /* Used for physical address casting */
  44.  
  45. /* Define possible tests */
  46. #define TestTx        0x01
  47. #define    TestRx        0x02
  48. #define    TestTxRx    0x03
  49.  
  50. /* Ethernet channel commands */
  51. #define    Configure    0x01
  52. #define    TxCmd        0x02
  53. #define    GetStatus    0x03
  54. #define    RxCmd        0x04
  55.  
  56. #define CmdPointer    0x00000000 /* Regsiter that holds the channel command pointer */
  57. #define InUse        0x80    /* Set the flag bit for command in use */
  58. #define TestSize    124
  59.  
  60. /**************************** Variable area ****************************/
  61.  
  62. /* Define the parameter block that controls the test */
  63. struct PB {
  64.     /* Put parameters here */
  65.     /* Put results here */
  66.     UWORD status;
  67.     } PB;
  68.     
  69. /* Carve out some space for channel commands */
  70. struct CC {
  71.     UBYTE    command;
  72.     UBYTE    flags;
  73.     UWORD    length;
  74.     ULONG    address;
  75.     } CC[0x20];
  76.  
  77. /* Transmit buffer */
  78. struct {
  79.     UBYTE Destination[6];
  80.     UBYTE Source[6];
  81.     UWORD Length;
  82.     UBYTE Buffer[1500];
  83.     /* The transmit source is four byte longer than the */
  84.     } TxPacket;
  85.     
  86. /* Receive buffer */
  87. struct {
  88.     UBYTE Destination[6];
  89.     UBYTE Source[6];
  90.     UWORD Length;
  91.     UBYTE Buffer[1500];
  92.     ULONG CRC;
  93.     } RxPacket;
  94.  
  95. /*************************** Constant Area *****************************/
  96.  
  97. MyNode[6]   = {0x52,0x6F,0x62,0x20,0x47,0x2E}; /* Source node */
  98. YourNode[6] = {0x10,0x00,0xE0,0x28,0x08,0x77}; /* Destination node */
  99.  
  100. /***************************** Code Area *******************************/
  101.  
  102. void MakeTxPacket(ULONG length) {
  103.     UWORD index;
  104.     /* Set source and destination addresses */
  105.     for (index=0;index<6;index++) {
  106.         TxPacket.Destination[index] = YourNode[index];
  107.         TxPacket.Source[index] = MyNode[index];
  108.         }
  109.     TxPacket.Length = Null; /* May be used later for variable packets */
  110.     /* Fill in the data field */
  111.     for (index=0;index<length;index++) {
  112.         TxPacket.Buffer[index] = index;
  113.         }
  114.     }
  115.  
  116. /*
  117. * This routine compares the data in the receive buffer. There are
  118. * several data types that are defined. This type is passed as a parameter
  119. * and is used to define the data for comparison
  120. * Type should be one of the follwoing values;
  121. * 0x00, 0x55, 0xAA, 0xFF, or 0x6A ('i' for incrementing from zero)
  122. * The node address, length field, and CRC are not compared
  123. */
  124. ComparePacket(UBYTE Type, ULONG length) {
  125.     ULONG index;
  126.     UBYTE failure = False;
  127.     if (Type = 'i') { /* incrementing pattern */
  128.         for (index=0;index<length;index++) {
  129.             if (RxPacket.Buffer[index] != index) {
  130.                 failure = True;
  131.                 break;
  132.                 }
  133.             }
  134.         }
  135.     else { /* Non incrementing */
  136.         for (index=0;index<length;index++) {
  137.             if (RxPacket.Buffer[index] != Type) {
  138.                 failure = True;
  139.                 break;
  140.                 }
  141.             }
  142.         }
  143.     }
  144.  
  145. TestTransmit() {
  146.     UWORD CommandPointer;
  147.     /* Build packet */
  148.     MakeTxPacket(TestSize);
  149.     /* Build tx channel command */
  150.     CommandPointer = 0; /* Point to first command */
  151.     CC[CommandPointer].command = TxCmd;
  152.     CC[CommandPointer].flags = InUse;
  153.     CC[CommandPointer].length = 124; /* 4 byte are appended for CRC */
  154.     CC[CommandPointer].address = &TxPacket;
  155.     /* Set channel command pointer in Mazda */
  156.     /* Wait for the results */
  157.     }
  158.  
  159. TestReceive() {
  160.     UWORD CommandPointer;
  161.     /* Build rx channel command */
  162.     CommandPointer = 0; /* Point to first command */
  163.     CC[CommandPointer].command = RxCmd;
  164.     CC[CommandPointer].flags = InUse;
  165.     CC[CommandPointer].length = 128;
  166.     CC[CommandPointer].address = &RxPacket;
  167.     /* Set channel command pointer in Mazda */
  168.     }
  169.  
  170. TestTransmitAndReceive() {
  171.     }
  172.  
  173. InitializeEthernet() {
  174.     /* Create initialization data block in memory */
  175.     /* Send Initialization command to Ethernet */
  176.     }
  177.  
  178. TestEthernet(TestType) {
  179.     InitializeEthernet();
  180.     switch(TestType) {
  181.         case TestTx :
  182.             TestTransmit();
  183.             break;
  184.         case TestRx :
  185.             TestReceive();
  186.             break;
  187.         case TestTxRx :
  188.             TestTransmitAndReceive();
  189.             break;
  190.         default :
  191.             /* Set error code for internal software error */
  192.             break;
  193.         }
  194.     }